package com.wsc.wisdomchinaqinghe.activitity.minemodule;

import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.wsc.wisdomchinaqinghe.R;
import com.wsc.wisdomchinaqinghe.Tools.JsonTools;
import com.wsc.wisdomchinaqinghe.Tools.Tools;
import com.wsc.wisdomchinaqinghe.activitity.baseactivity.BaseActivity;
import com.wsc.wisdomchinaqinghe.callback.ContributorView;
import com.wsc.wisdomchinaqinghe.javaBean.BaoMingDetailBean;
import com.wsc.wisdomchinaqinghe.javaBean.RespObj;
import com.wsc.wisdomchinaqinghe.presenter.ContributorPresenter;
import com.wsc.wisdomchinaqinghe.view.MyToast;

public class BaoMingDetailActivity extends BaseActivity implements ContributorView,View.OnClickListener {

    private ImageView  regist_back,iv_head;
    private TextView tv_headtitle,activity_wdfk_bxjdxq_slove,tv_title,tv_time,activity_wdfk_bxjdxq_time,tv_name,tv_sex,tv_phone,tv_cancel;
    private TextView et_remark;

    private ContributorPresenter contributorPresenter;
    private Context context;
    private final String DETAILFLAG=BaoMingDetailActivity.class.getSimpleName();
    private final String DELETEHOUSEDELETEFLAG="DELETEHOUSEDELETEFLAG";
    private MyToast myToast;
    private String deleteId;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.baomingdetail_layout);
        initView();
        context=this;
        myToast=new MyToast(context);
        contributorPresenter = new ContributorPresenter(this, context);
        Intent intent=getIntent();
        deleteId=intent.getStringExtra("id");
        contributorPresenter.getBuildingCommunityActivityDetail(deleteId,DETAILFLAG);
    }

    private void initView() {
        activity_wdfk_bxjdxq_slove = (TextView) findViewById(R.id.activity_wdfk_bxjdxq_slove);//状态
        activity_wdfk_bxjdxq_time = (TextView) findViewById(R.id.activity_wdfk_bxjdxq_time);//报名时间
        regist_back=(ImageView) findViewById(R.id.regist_back);
        regist_back.setOnClickListener(this);
        tv_headtitle=(TextView) findViewById(R.id.tv_headtitle);
        tv_headtitle.setText("报名详情");
        tv_headtitle.requestFocus();
        tv_headtitle.setFocusable(true);
        tv_headtitle.setFocusableInTouchMode(true);
        iv_head=(ImageView) findViewById(R.id.iv_head);
        tv_title= (TextView) findViewById(R.id.tv_title);
        tv_time= (TextView) findViewById(R.id.tv_time);
        tv_name= (TextView) findViewById(R.id.tv_name);
        tv_sex= (TextView) findViewById(R.id.tv_sex);
        tv_phone= (TextView) findViewById(R.id.tv_phone);
        tv_cancel= (TextView) findViewById(R.id.tv_cancel);
        tv_cancel.setOnClickListener(this);
        et_remark=(TextView) findViewById(R.id.et_remark);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId())
        {
            case R.id.regist_back:
                finish();
                break;
            case R.id.tv_cancel:
                contributorPresenter.getCommunityActivityDelete(deleteId,DELETEHOUSEDELETEFLAG);
                break;
        }
    }

    @Override
    public void onLoadContributorStart(String flag) {

    }


    @Override
    public void onLoadContributorSuccess(String jsonString, String flag) {
        try {
            if(flag.equals(DELETEHOUSEDELETEFLAG)) {
                RespObj respObj = JsonTools.jsonStringToObject(jsonString, RespObj.class);
                String code = respObj.getCode();
                Object object = respObj.getMessage();
                if (code.equals("200") && object != null) {
                    String jsonMessage = (String) object;
                    if(jsonMessage.equals("41"))
                    {
                        myToast.showShort("删除成功");
                        Intent intent=getIntent();
                        setResult(1,intent);
                        finish();
                    }else {
                        myToast.showShort("删除失败");
                    }
                }else
                {
                    myToast.showShort("删除失败");
                }
            }else if (flag.equals(DETAILFLAG)) {
                RespObj respObj = JsonTools.jsonStringToObject(jsonString, RespObj.class);
                String code = respObj.getCode();
                Object object = respObj.getMessage();
                if (code.equals("200") && object != null) {
                    String jsonMessage = JsonTools.objectToJsonString(object);
                    BaoMingDetailBean baoMingDetailBean = JsonTools.jsonStringToObject(jsonMessage, BaoMingDetailBean.class);
                    if (baoMingDetailBean != null) {
                        if (baoMingDetailBean.getState() == 0) {
                            activity_wdfk_bxjdxq_slove.setText("待审核");
                            activity_wdfk_bxjdxq_slove.setTextColor(context.getResources().getColor(R.color.little_white));
                        } else if (baoMingDetailBean.getState() == 1) {
                            activity_wdfk_bxjdxq_slove.setText("报名成功");
                            activity_wdfk_bxjdxq_slove.setTextColor(Color.GREEN);
                        } else if (baoMingDetailBean.getState() == 2) {
                            activity_wdfk_bxjdxq_slove.setText("报名失败");
                            activity_wdfk_bxjdxq_slove.setTextColor(Color.RED);
                        }

                        String date_time = Tools.timedate(String.valueOf(baoMingDetailBean.getSignTime() / 1000));
                        activity_wdfk_bxjdxq_time.setText(date_time);

                        Glide.with(this).load(baoMingDetailBean.getGuideImg()).into(iv_head);

                        tv_title.setText(baoMingDetailBean.getTitle());
                        tv_time.setText( Tools.timedate(String.valueOf(baoMingDetailBean.getCreateDate() / 1000)));
                        tv_name.setText(baoMingDetailBean.getName());
                        if(baoMingDetailBean.getGender()==0)
                        {
                            tv_sex.setText("女");
                        } else
                        {
                            tv_sex.setText("男");
                        }
                        tv_phone.setText(baoMingDetailBean.getPhone());
                        et_remark.setText(baoMingDetailBean.getRemark());

                    }

                }
            }

        } catch (Exception e) {

        }
    }


    @Override
    public void onLoadContributorComplete(String flag) {
    }

    @Override
    public void onLoadContributorError(String error, String flag) {
    }

}
